package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.Designer;
import com.ysd.uitl.DBManager;

public class DesignerDaoImpl {
	public List<Designer> getDesignerList() {
		List<Designer> designerList = new ArrayList<Designer>();
		Connection conn = DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			rs = st.executeQuery("select * from designer");
			while (rs.next()) {//好像也没啥错。。
				int designerId = rs.getInt(1);// 代码应该没错，但是填写字段名确实获取不到designerId和position。。 原因不详
				String name = rs.getString(2);//如果字段名不能用， 那么就用列号也可以
				String position = rs.getString(3);
				String img = rs.getString(4);
				Designer designer = new Designer(designerId, name, position, img);
				designerList.add(designer);
			}
			return designerList;
		} catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
}
